<script>
import { mapState } from 'vuex'
import { config, column } from './formConfig.js'
import BasicManage from '@/components/basic/BasicManage.vue'

export default {
    extends: BasicManage,
    data() {
        return {
            table_title: '终端类型',
            url: 'sensorType',
            dialog: {
                config: [],
                form: {},
                title: '',
                labelWidth: '130px',
            },
            baseForm: {
                name: '',
                characters: '',
                accelerate: '',
                eigenvalue: null,
                feature_tag: null,
                domain: null,
                show: 1,
            },
        }
    },
    computed: {
        ...mapState('backstage', ['domainTags', 'eigenvalueTags', 'waveTags', 'sys_eig', 'sys_wave']),
    },
    methods: {
        from(data) {
            data.eigenvalue = this.none.includes(data.eigenvalue) ? data.eigenvalue : data.eigenvalue.split(',').map((item) => parseInt(item))
            data.sys_eig = this.none.includes(data.sys_eig) ? data.sys_eig : data.sys_eig.split(',').map((item) => parseInt(item))
            data.sys_wave = this.none.includes(data.sys_wave) ? data.sys_wave : data.sys_wave.split(',').map((item) => parseInt(item))
            data.feature_tag = this.none.includes(data.feature_tag) ? data.feature_tag : data.feature_tag.split(',').map((item) => parseInt(item))
            data.domain = this.none.includes(data.domain) ? data.domain : data.domain.split(',').map((item) => parseInt(item))
            return data
        },
        to(data) {
            data.eigenvalue = this.none.includes(data.eigenvalue) ? data.eigenvalue : data.eigenvalue.join(',')
            data.sys_eig = this.none.includes(data.sys_eig) ? data.sys_eig : data.sys_eig.join(',')
            data.sys_wave = this.none.includes(data.sys_wave) ? data.sys_wave : data.sys_wave.join(',')
            data.feature_tag = this.none.includes(data.feature_tag) ? data.feature_tag : data.feature_tag.join(',')
            data.domain = this.none.includes(data.domain) ? data.domain : data.domain.join(',')
            return data
        },
    },
    created() {
        column[column.length - 1].buttons = [
            {
                text: '编辑',
                click: (val) => {
                    this.handleEdit(val)
                },
                icon: 'el-icon-edit',
            },
            {
                text: '删除',
                click: (val) => {
                    this.delete(val)
                },
                icon: 'el-icon-delete',
            },
        ]
        column[column.length - 1].if = this.operate
        config[5].options = this.eigenvalueTags

        config[7].options = this.domainTags
        config[8].options = this.waveTags

        config[9].options = this.sys_eig
        config[10].options = this.sys_wave

        this.dialog.config = config
        this.tableColumn = column
        this.getlist()
    },
}
</script>
